package com.nemlistapp;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class States {
	
	private static States instance;
	private String userName;
	private String token;
	private int createUserState = -1;
	private ShoppingList currentShoppingList;
	
	private States()
	{
		
	}
	
	public static States getInstance()
	{
		if(instance == null)
		{
			instance = new States();
		}
		return instance;
	}
	
	public String getUserName()
	{
		return userName;
	}
	
	public String getToken()
	{
		return token;
	}
	
	public ShoppingList getCurrentShoppingList()
	{
		return currentShoppingList;
	}
	
	public int getCreateUserState()
	{
		return createUserState;
	}
	
	public void setUserName(String userName)
	{
		this.userName = userName;
	}
	
	public void setToken(String token)
	{
		this.token = token;
	}
	
	public void setCurrentShoppingList(ShoppingList currentShoppingList)
	{
		this.currentShoppingList = currentShoppingList;
	}
	
	public void setCreateUserState(int createUserState)
	{
		this.createUserState = createUserState;
	}
	
	public void setPreferences(Context context)
	{
		Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.putString("UserNamePreference", getUserName());   
        editor.putString("TokenPreference", getToken());
        editor.commit();
	}
	
	
	public States getPreferences(Context context)
	{		
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
		if(prefs != null)
		{
		setUserName(prefs.getString("UserNamePreference", null)); 
		setToken(prefs.getString("TokenPreference", null));		
		}
		
		return getInstance();
	}
	
}


